﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Galaxy.AutoCAD.Windows;
using Galaxy.AutoCAD.Options;
using Autodesk.AutoCAD.Geometry;
using Galaxy.AutoCAD.Editors;
using Galaxy.AutoCAD.Databases;

[assembly: CommandClass(typeof(Galaxy.AutoCAD.Methods.RebarMethodTool))]
namespace Galaxy.AutoCAD.Methods
{
    public class RebarMethodTool
    {
        #region 创建闭口箍筋图层
        [CommandMethod("CSSL")]
        public static void CreateSilentStirrupLayer()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                if (!db.HasLayer("Galaxy-钢筋-箍筋-闭口"))
                {
                    ObjectId objectId = db.AddLayer("Galaxy-钢筋-箍筋-闭口", 1);
                }
            }
            catch
            {

            }
        }
        #endregion
        #region 绘制闭口箍筋
        [CommandMethod("DSS")]
        public static void DrawSilentStirrup()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            if (!db.HasLayer("Galaxy-钢筋-箍筋-闭口"))
            {
                Application.ShowAlertDialog("请先点击钢筋前置条件!");
            }
            else
            {
                db.SetCurrentLayer("Galaxy-钢筋-箍筋-闭口");
                using (SilentStirrupWindows ssw = new SilentStirrupWindows())
                {
                    Application.ShowModalDialog(ssw);
                }
                string silentStirrupPass = RebarOptionTool.SilentStirrupPass;
                uint silentStirrupCoveringLayer = RebarOptionTool.SilentStirrupCoveringLayer;
                string silentStirrupGrade = RebarOptionTool.SilentStirrupGrade;
                uint silentStirrupDirect = RebarOptionTool.SilentStirrupDirect;
                string silentStirrupClosedPosition = RebarOptionTool.SilentStirrupClosedPosition;
                //Application.ShowAlertDialog(silentStirrupPass + "\t\n" + silentStirrupCoveringLayer.ToString() + "\t\n" + silentStirrupGrade + "\t\n" + silentStirrupDirect.ToString() + "\t\n" + silentStirrupOpenPosition);
                if (silentStirrupPass == "1")
                {
                    Point3d firstPoint3d = ed.InputPoint("请输入第一点！");
                    if (firstPoint3d != null)
                    {
                        Point3d secondPoint3d = ed.InputPoint("请输入第二点！");
                        if (secondPoint3d != null)
                        {
                            Point3d minPoint3d = new Point3d(Math.Min(firstPoint3d.X, secondPoint3d.X), Math.Min(firstPoint3d.Y, secondPoint3d.Y), firstPoint3d.Z);
                            Point3d maxPoint3d = new Point3d(Math.Max(firstPoint3d.X, secondPoint3d.X), Math.Max(firstPoint3d.Y, secondPoint3d.Y), firstPoint3d.Z);
                            Point2d pt1 = new Point2d(minPoint3d.X + silentStirrupCoveringLayer, minPoint3d.Y + silentStirrupCoveringLayer);
                            Point2d pt2 = new Point2d(maxPoint3d.X - silentStirrupCoveringLayer, maxPoint3d.Y - silentStirrupCoveringLayer);
                            if (silentStirrupDirect == 6)
                            {
                                if (silentStirrupClosedPosition == "左上角")
                                {
                                    Point2d pt2d3 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d2 = new Point2d(pt1.X, pt2.Y - 50);
                                    Point2d pt2d8 = new Point2d(pt1.X + 50, pt2.Y);
                                    Point2d pt2d1 = new Point2d(pt2d2.X + 75 / Math.Sqrt(2.0), pt2d2.Y - 75 / Math.Sqrt(2.0));
                                    Point2d pt2d9 = new Point2d(pt2d8.X + 75 / Math.Sqrt(2.0), pt2d8.Y - 75 / Math.Sqrt(2.0));
                                    Point2d pt2d4 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d5 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d6 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d7 = new Point2d(pt1.X, pt2.Y);
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    pts.Add(pt2d7);
                                    pts.Add(pt2d8);
                                    pts.Add(pt2d9);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, silentStirrupDirect, silentStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (silentStirrupClosedPosition == "左下角")
                                {
                                    Point2d pt2d3 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d4 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d5 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d6 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d7 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d2 = new Point2d(pt1.X + 50, pt1.Y);
                                    Point2d pt2d8 = new Point2d(pt1.X, pt1.Y + 50);
                                    Point2d pt2d1 = new Point2d(pt2d2.X + 75 / Math.Sqrt(2.0), pt2d2.Y + 75 / Math.Sqrt(2.0));
                                    Point2d pt2d9 = new Point2d(pt2d8.X + 75 / Math.Sqrt(2.0), pt2d8.Y + 75 / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    pts.Add(pt2d7);
                                    pts.Add(pt2d8);
                                    pts.Add(pt2d9);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, silentStirrupDirect, silentStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (silentStirrupClosedPosition == "右上角")
                                {
                                    Point2d pt2d3 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d4 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d5 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d6 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d7 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d2 = new Point2d(pt2.X - 50, pt2.Y);
                                    Point2d pt2d8 = new Point2d(pt2.X, pt2.Y - 50);
                                    Point2d pt2d1 = new Point2d(pt2d2.X - 75 / Math.Sqrt(2.0), pt2d2.Y - 75 / Math.Sqrt(2.0));
                                    Point2d pt2d9 = new Point2d(pt2d8.X - 75 / Math.Sqrt(2.0), pt2d8.Y - 75 / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    pts.Add(pt2d7);
                                    pts.Add(pt2d8);
                                    pts.Add(pt2d9);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, silentStirrupDirect, silentStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (silentStirrupClosedPosition == "右下角")
                                {
                                    Point2d pt2d3 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d4 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d5 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d6 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d7 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d2 = new Point2d(pt2.X, pt1.Y + 50);
                                    Point2d pt2d8 = new Point2d(pt2.X - 50, pt1.Y);
                                    Point2d pt2d1 = new Point2d(pt2d2.X - 75 / Math.Sqrt(2.0), pt2d2.Y + 75 / Math.Sqrt(2.0));
                                    Point2d pt2d9 = new Point2d(pt2d8.X - 75 / Math.Sqrt(2.0), pt2d8.Y + 75 / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    pts.Add(pt2d7);
                                    pts.Add(pt2d8);
                                    pts.Add(pt2d9);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, silentStirrupDirect, silentStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                            }
                            else
                            {
                                if (silentStirrupClosedPosition == "左上角")
                                {
                                    Point2d pt2d3 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d2 = new Point2d(pt1.X, pt2.Y - 50);
                                    Point2d pt2d8 = new Point2d(pt1.X + 50, pt2.Y);
                                    Point2d pt2d1 = new Point2d(pt2d2.X + silentStirrupDirect * 10 / Math.Sqrt(2.0), pt2d2.Y - silentStirrupDirect * 10 / Math.Sqrt(2.0));
                                    Point2d pt2d9 = new Point2d(pt2d8.X + silentStirrupDirect * 10 / Math.Sqrt(2.0), pt2d8.Y - silentStirrupDirect * 10 / Math.Sqrt(2.0));
                                    Point2d pt2d4 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d5 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d6 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d7 = new Point2d(pt1.X, pt2.Y);
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    pts.Add(pt2d7);
                                    pts.Add(pt2d8);
                                    pts.Add(pt2d9);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, silentStirrupDirect, silentStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (silentStirrupClosedPosition == "左下角")
                                {
                                    Point2d pt2d3 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d4 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d5 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d6 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d7 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d2 = new Point2d(pt1.X + 50, pt1.Y);
                                    Point2d pt2d8 = new Point2d(pt1.X, pt1.Y + 50);
                                    Point2d pt2d1 = new Point2d(pt2d2.X + silentStirrupDirect * 10 / Math.Sqrt(2.0), pt2d2.Y + silentStirrupDirect * 10 / Math.Sqrt(2.0));
                                    Point2d pt2d9 = new Point2d(pt2d8.X + silentStirrupDirect * 10 / Math.Sqrt(2.0), pt2d8.Y + silentStirrupDirect * 10 / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    pts.Add(pt2d7);
                                    pts.Add(pt2d8);
                                    pts.Add(pt2d9);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, silentStirrupDirect, silentStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (silentStirrupClosedPosition == "右上角")
                                {
                                    Point2d pt2d3 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d4 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d5 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d6 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d7 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d2 = new Point2d(pt2.X - 50, pt2.Y);
                                    Point2d pt2d8 = new Point2d(pt2.X, pt2.Y - 50);
                                    Point2d pt2d1 = new Point2d(pt2d2.X - silentStirrupDirect * 10 / Math.Sqrt(2.0), pt2d2.Y - silentStirrupDirect * 10 / Math.Sqrt(2.0));
                                    Point2d pt2d9 = new Point2d(pt2d8.X - silentStirrupDirect * 10 / Math.Sqrt(2.0), pt2d8.Y - silentStirrupDirect * 10 / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    pts.Add(pt2d7);
                                    pts.Add(pt2d8);
                                    pts.Add(pt2d9);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, silentStirrupDirect, silentStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (silentStirrupClosedPosition == "右下角")
                                {
                                    Point2d pt2d3 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d4 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d5 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d6 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d7 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d2 = new Point2d(pt2.X, pt1.Y + 50);
                                    Point2d pt2d8 = new Point2d(pt2.X - 50, pt1.Y);
                                    Point2d pt2d1 = new Point2d(pt2d2.X - silentStirrupDirect * 10 / Math.Sqrt(2.0), pt2d2.Y + silentStirrupDirect * 10 / Math.Sqrt(2.0));
                                    Point2d pt2d9 = new Point2d(pt2d8.X - silentStirrupDirect * 10 / Math.Sqrt(2.0), pt2d8.Y + silentStirrupDirect * 10 / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    pts.Add(pt2d7);
                                    pts.Add(pt2d8);
                                    pts.Add(pt2d9);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, silentStirrupDirect, silentStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                            }
                        }
                    }
                }
            }
            db.SetCurrentLayer("0");
        }
        #endregion
        #region 创建开口箍筋图层
        [CommandMethod("COSL")]
        public static void CreateOpeningStirrupLayer()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                if (!db.HasLayer("Galaxy-钢筋-箍筋-开口"))
                {
                    ObjectId objectId = db.AddLayer("Galaxy-钢筋-箍筋-开口", 1);
                }
            }
            catch
            {

            }
        }
        #endregion
        #region 绘制开口箍筋
        [CommandMethod("DOS")]
        public static void DrawOpeningStirrup()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            if (!db.HasLayer("Galaxy-钢筋-箍筋-开口"))
            {
                Application.ShowAlertDialog("请先点击钢筋前置条件!");
            }
            else
            {
                db.SetCurrentLayer("Galaxy-钢筋-箍筋-开口");
                using (OpeningStirrupWindows osw = new OpeningStirrupWindows())
                {
                    Application.ShowModalDialog(osw);
                }
                string openingStirrupPass = RebarOptionTool.OpeningStirrupPass;
                uint openingStirrupCoveringLayer = RebarOptionTool.OpeningStirrupCoveringLayer;
                string openingStirrupGrade = RebarOptionTool.OpeningStirrupGrade;
                uint openingStirrupDirect = RebarOptionTool.OpeningStirrupDirect;
                string openingStirrupClosedPosition = RebarOptionTool.OpeningStirrupClosedPosition;
                //Application.ShowAlertDialog(openingStirrupPass + "\t\n" + openingStirrupCoveringLayer.ToString() + "\t\n" + openingStirrupGrade + "\t\n" + openingStirrupDirect.ToString() + "\t\n" + openingStirrupClosedPosition);
                if (openingStirrupPass == "1")
                {
                    Point3d firstPoint3d = ed.InputPoint("请输入第一点！");
                    if (firstPoint3d != null)
                    {
                        Point3d secondPoint3d = ed.InputPoint("请输入第二点！");
                        if (secondPoint3d != null)
                        {
                            Point3d minPoint3d = new Point3d(Math.Min(firstPoint3d.X, secondPoint3d.X), Math.Min(firstPoint3d.Y, secondPoint3d.Y), firstPoint3d.Z);
                            Point3d maxPoint3d = new Point3d(Math.Max(firstPoint3d.X, secondPoint3d.X), Math.Max(firstPoint3d.Y, secondPoint3d.Y), firstPoint3d.Z);
                            Point2d pt1 = new Point2d(minPoint3d.X + openingStirrupCoveringLayer, minPoint3d.Y + openingStirrupCoveringLayer);
                            Point2d pt2 = new Point2d(maxPoint3d.X - openingStirrupCoveringLayer, maxPoint3d.Y - openingStirrupCoveringLayer);
                            if (openingStirrupDirect == 6)
                            {
                                if (openingStirrupClosedPosition == "上")
                                {
                                    Point2d pt2d2 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d3 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d4 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d5 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d6 = new Point2d(pt2d5.X + 75 / Math.Sqrt(2.0), pt2d5.Y - 75 / Math.Sqrt(2.0));
                                    Point2d pt2d1 = new Point2d(pt2d2.X - 75 / Math.Sqrt(2.0), pt2d2.Y - 75 / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, openingStirrupDirect, openingStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (openingStirrupClosedPosition == "下")
                                {
                                    Point2d pt2d2 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d3 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d4 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d5 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d6 = new Point2d(pt2d5.X - 75 / Math.Sqrt(2.0), pt2d5.Y + 75 / Math.Sqrt(2.0));
                                    Point2d pt2d1 = new Point2d(pt2d2.X + 75 / Math.Sqrt(2.0), pt2d2.Y + 75 / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, openingStirrupDirect, openingStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (openingStirrupClosedPosition == "左")
                                {
                                    Point2d pt2d2 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d3 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d4 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d5 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d6 = new Point2d(pt2d5.X + 75 / Math.Sqrt(2.0), pt2d5.Y + 75 / Math.Sqrt(2.0));
                                    Point2d pt2d1 = new Point2d(pt2d2.X + 75 / Math.Sqrt(2.0), pt2d2.Y - 75 / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, openingStirrupDirect, openingStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (openingStirrupClosedPosition == "右")
                                {
                                    Point2d pt2d2 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d3 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d4 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d5 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d6 = new Point2d(pt2d5.X - 75 / Math.Sqrt(2.0), pt2d5.Y - 75 / Math.Sqrt(2.0));
                                    Point2d pt2d1 = new Point2d(pt2d2.X - 75 / Math.Sqrt(2.0), pt2d2.Y + 75 / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, openingStirrupDirect, openingStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                            }
                            else
                            {
                                if (openingStirrupClosedPosition == "上")
                                {
                                    Point2d pt2d2 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d3 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d4 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d5 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d6 = new Point2d(pt2d5.X + 10* openingStirrupDirect / Math.Sqrt(2.0), pt2d5.Y - 10 * openingStirrupDirect / Math.Sqrt(2.0));
                                    Point2d pt2d1 = new Point2d(pt2d2.X - 10 * openingStirrupDirect / Math.Sqrt(2.0), pt2d2.Y - 10 * openingStirrupDirect / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, openingStirrupDirect, openingStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (openingStirrupClosedPosition == "下")
                                {
                                    Point2d pt2d2 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d3 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d4 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d5 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d6 = new Point2d(pt2d5.X - 10 * openingStirrupDirect / Math.Sqrt(2.0), pt2d5.Y + 10 * openingStirrupDirect / Math.Sqrt(2.0));
                                    Point2d pt2d1 = new Point2d(pt2d2.X + 10 * openingStirrupDirect / Math.Sqrt(2.0), pt2d2.Y + 10 * openingStirrupDirect / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, openingStirrupDirect, openingStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (openingStirrupClosedPosition == "左")
                                {
                                    Point2d pt2d2 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d3 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d4 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d5 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d6 = new Point2d(pt2d5.X + 10 * openingStirrupDirect / Math.Sqrt(2.0), pt2d5.Y + 10 * openingStirrupDirect / Math.Sqrt(2.0));
                                    Point2d pt2d1 = new Point2d(pt2d2.X + 10 * openingStirrupDirect / Math.Sqrt(2.0), pt2d2.Y - 10 * openingStirrupDirect / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, openingStirrupDirect, openingStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                                if (openingStirrupClosedPosition == "右")
                                {
                                    Point2d pt2d2 = new Point2d(pt2.X, pt1.Y);
                                    Point2d pt2d3 = new Point2d(pt1.X, pt1.Y);
                                    Point2d pt2d4 = new Point2d(pt1.X, pt2.Y);
                                    Point2d pt2d5 = new Point2d(pt2.X, pt2.Y);
                                    Point2d pt2d6 = new Point2d(pt2d5.X - 10 * openingStirrupDirect / Math.Sqrt(2.0), pt2d5.Y - 10 * openingStirrupDirect / Math.Sqrt(2.0));
                                    Point2d pt2d1 = new Point2d(pt2d2.X - 10 * openingStirrupDirect / Math.Sqrt(2.0), pt2d2.Y + 10 * openingStirrupDirect / Math.Sqrt(2.0));
                                    Point2dCollection pts = new Point2dCollection();
                                    pts.Add(pt2d1);
                                    pts.Add(pt2d2);
                                    pts.Add(pt2d3);
                                    pts.Add(pt2d4);
                                    pts.Add(pt2d5);
                                    pts.Add(pt2d6);
                                    Polyline pl = new Polyline();
                                    pl.CreatePolyline(pts, openingStirrupDirect, openingStirrupDirect);
                                    ObjectId objectId2 = db.AddToModelSpace(pl);
                                }
                            }
                        }
                    }
                }
            }
            db.SetCurrentLayer("0");
        }
        #endregion
    }
}
